package com.exchange.Controller;

import android.content.Context;
import android.content.res.Configuration;
import com.exchange.Public.ExchangeConstants;
import com.exchange.Public.h;
import com.exchange.Public.m;
import com.exchange.Public.n;
import com.exchange.Public.o;
import com.exchange.b.a;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class a extends Thread
{
  private String a;

  public a(int paramInt1, Context paramContext, com.exchange.b.a parama, int paramInt2, int paramInt3, int paramInt4)
  {
    ArrayList localArrayList = new ArrayList();
    localArrayList.add(parama);
    this.a = a(paramContext, paramInt1, paramInt4, paramInt3, paramInt2, localArrayList, 0);
  }

  public a(int paramInt1, Context paramContext, com.exchange.b.a parama, int paramInt2, int paramInt3, int paramInt4, int paramInt5)
  {
    ArrayList localArrayList = new ArrayList();
    localArrayList.add(parama);
    this.a = a(paramContext, paramInt1, paramInt4, paramInt3, paramInt2, localArrayList, paramInt5);
  }

  public a(int paramInt1, Context paramContext, List<com.exchange.b.a> paramList, int paramInt2, int paramInt3, int paramInt4, int paramInt5)
  {
    this.a = a(paramContext, paramInt1, paramInt4, paramInt3, paramInt2, paramList, paramInt5);
  }

  public a(Context paramContext, int paramInt1, List<com.exchange.b.a> paramList, int paramInt2, int paramInt3, int paramInt4)
  {
    this.a = a(paramContext, paramInt1, paramInt4, paramInt3, paramInt2, paramList, 0);
    n.a("xuzhen", "xuzhen " + this.a);
  }

  public a(String paramString)
  {
    this.a = paramString;
  }

  private int a(String paramString)
  {
    String str2;
    int j;
    String str1 = null;
    int i = 0;
    while (true)
    {
      if (i >= ExchangeConstants.REPORT_URL_LIST.length)
        str2 = str1;
      while (true)
      {
        if (str2 != null)
          break label110;
        j = -1;
        return j;
        n.c(ExchangeConstants.LOG_TAG, "report to " + ExchangeConstants.REPORT_URL_LIST[i] + ": " + paramString);
        str1 = o.a(paramString, ExchangeConstants.REPORT_URL_LIST[i]);
        n.c(ExchangeConstants.LOG_TAG, "report result:" + str1);
        if (str1 == null)
          break;
        str2 = str1;
      }
      ++i;
    }
    try
    {
      while (true)
      {
        label110: boolean bool = "ok".equals(new JSONObject(str2).getString("success"));
        if (!(bool))
          break;
        j = 1;
      }
      j = 0;
    }
    catch (JSONException localJSONException)
    {
      localJSONException.printStackTrace();
      j = -2;
    }
  }

  public static String a()
  {
    return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
  }

  public static String a(Context paramContext, int paramInt1, int paramInt2, int paramInt3, int paramInt4, List<com.exchange.b.a> paramList, int paramInt5)
  {
    JSONArray localJSONArray;
    int i;
    int j;
    JSONObject localJSONObject1 = new JSONObject();
    try
    {
      localJSONObject1.put("page_level", paramInt3);
      localJSONObject1.put("promotion_type", paramInt4);
      localJSONObject1.put("channel", m.a(paramContext));
      localJSONObject1.put("protocol_version", ExchangeConstants.protocol_version);
      localJSONObject1.put("sdk_version", ExchangeConstants.sdk_version);
      if (paramInt5 != 0)
        localJSONObject1.put("display_style", paramInt5);
      localJSONObject1.put("sid", ExchangeConstants.sid);
      localJSONObject1.put("device_id", h.i(paramContext));
      localJSONObject1.put("publisher", h.f(paramContext));
      String str1 = a();
      String str2 = str1.split(" ")[0];
      String str3 = str1.split(" ")[1];
      localJSONObject1.put("date", str2);
      localJSONObject1.put("time", str3);
      Calendar localCalendar = Calendar.getInstance(new Configuration().locale);
      if (localCalendar != null)
      {
        TimeZone localTimeZone = localCalendar.getTimeZone();
        if (localTimeZone != null)
        {
          localJSONObject1.put("timezone", localTimeZone.getRawOffset() / 3600000);
          localJSONArray = new JSONArray();
          i = paramList.size();
          j = 0;
          if (j < i)
            break label287;
          localJSONObject1.put("promoters", localJSONArray);
          return localJSONObject1.toString();
        }
        label287: localJSONObject1.put("timezone", 8);
      }
    }
    catch (Exception localException)
    {
      while (true)
      {
        while (true)
          localException.printStackTrace();
        localJSONObject1.put("timezone", 8);
      }
      com.exchange.b.a locala = (com.exchange.b.a)paramList.get(j);
      JSONObject localJSONObject2 = new JSONObject();
      localJSONObject2.put("promoter", locala.j);
      localJSONObject2.put("category", locala.l);
      localJSONObject2.put("landing_type", locala.r);
      locala.v = paramInt1;
      localJSONObject2.put("action", locala.v);
      localJSONObject2.put("bid", locala.k);
      if (i > 1)
        localJSONObject2.put("action_index", j);
      while (true)
      {
        while (true)
        {
          localJSONArray.put(localJSONObject2);
          ++j;
        }
        localJSONObject2.put("action_index", paramInt2);
      }
    }
  }

  public void run()
  {
    try
    {
      a(this.a);
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }
}